﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataVisit.Model;
using NHibernate.Transform;
using System.Collections;

namespace DataVisit.DAL.ReportData
{
    public class DRecycling:AbstractSupportDal<IProjectModel>
    {
        /// <summary>
        /// 得到回收报表数据
        /// </summary>
        /// <param name="time">时间</param>
        /// <param name="name">队名</param>
        /// <returns></returns>
        public IList GetRecycling_HS(string time,string name) 
        {
            try 
            {
                return Session.GetNamedQuery("GetHs")
                    .SetString("year",getDateStr(time,"1"))
                    .SetString("month",getDateStr(time,"2"))
                    .SetString("groupName",name)
                    .SetResultTransformer(Transformers.AliasToEntityMap).List();
            }catch{
                return null;
            }
        }

        /// <summary>
        /// 得到复用报表数据
        /// </summary>
        /// <param name="time">时间</param>
        /// <param name="name">队名</param>
        /// <returns></returns>
        public IList GetRecycling_FY(string time, string name)
        {
            try
            {
                return Session.GetNamedQuery("GetFy")
                    .SetString("year", getDateStr(time, "1"))
                    .SetString("month", getDateStr(time, "2"))
                    .SetString("groupName", name)
                    .SetResultTransformer(Transformers.AliasToEntityMap).List();
            }
            catch
            {
                return null;
            }
        }

        private string getDateStr(string time,string t)
        { 
            string s="";
            if(t =="1")
            {
                s=Convert.ToDateTime(time).ToString("yyyy-MM-dd").Split('-')[0];
            }
            if(t =="2")
            {
                s=Convert.ToDateTime(time).ToString("yyyy-MM-dd").Split('-')[1];
            }
            return s;
        }
    }
}
